package com.springCloud.main;

/**
 * @ClassName MathMain
 * @Author 1628994918qq.com
 * @Date 2023/3/31 15:04
 * 检查一个字符串中只包含数字
 */
public class MathMain {
    public static void main(String[] args) {
        //String str = "acs226qqe122";
        String str = "2222215566";
        boolean b = checkNumber(str);
        System.out.println(b);
    }

    public static boolean checkNumber(String str){
        char[] chars = str.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            //charAt 截取字符
            char c = str.charAt(i);
            //isDigit() 判断是否为数字
            if (!Character.isDigit(c)){
                return false;
            }
        }
        return true;
    }
}
